package com.example.smsquiz;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

/**
 * Created by Dmitry Kuyanov
 * Date: 07.03.13
 * Time: 10:42
 */
public class SetAnswerActivity extends Activity {

    public static final String QUESTION_KEY = "QuestionKey";

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_answer);
        Intent questionIntent = getIntent();
        String question = questionIntent.getStringExtra(QUESTION_KEY);
        EditText questionEdit = (EditText) findViewById(R.id.editQuestion);
        questionEdit.setText(question);
    }

    public void onClickAddQuestion(View v){
        try{
            String question = String.valueOf(((EditText) findViewById(R.id.editQuestion)).getText());
            String answer = String.valueOf(((EditText) findViewById(R.id.editAnswer)).getText());
            AppModel.getInstance().addQuestion(question, answer);
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            AlertDialog dialog = builder.create();
            dialog.setMessage("Question was added into database");
            dialog.show();
            AppModel.getInstance().setQuestionProcessing(false);
        }
        catch (Exception ex){
            AppLogger.WriteError(ex);
        }
    }
}